<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>size_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_math_size_test.js.html">size_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2006 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.math.SizeTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.math.SizeTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.math.Size&#39;);
<a name="line19"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line20"></a>
<a name="line21"></a>function testSize1() {
<a name="line22"></a>  var s = new goog.math.Size(undefined, undefined);
<a name="line23"></a>  assertUndefined(s.width);
<a name="line24"></a>  assertUndefined(s.height);
<a name="line25"></a>  assertEquals(&#39;(undefined x undefined)&#39;, s.toString());
<a name="line26"></a>}
<a name="line27"></a>
<a name="line28"></a>function testSize3() {
<a name="line29"></a>  var s = new goog.math.Size(10, 20);
<a name="line30"></a>  assertEquals(10, s.width);
<a name="line31"></a>  assertEquals(20, s.height);
<a name="line32"></a>  assertEquals(&#39;(10 x 20)&#39;, s.toString());
<a name="line33"></a>}
<a name="line34"></a>
<a name="line35"></a>function testSize4() {
<a name="line36"></a>  var s = new goog.math.Size(10.5, 20.897);
<a name="line37"></a>  assertEquals(10.5, s.width);
<a name="line38"></a>  assertEquals(20.897, s.height);
<a name="line39"></a>  assertEquals(&#39;(10.5 x 20.897)&#39;, s.toString());
<a name="line40"></a>}
<a name="line41"></a>
<a name="line42"></a>function testSizeClone() {
<a name="line43"></a>  var s = new goog.math.Size(undefined, undefined);
<a name="line44"></a>  assertEquals(s.toString(), s.clone().toString());
<a name="line45"></a>  s.width = 4;
<a name="line46"></a>  s.height = 5;
<a name="line47"></a>  assertEquals(s.toString(), s.clone().toString());
<a name="line48"></a>}
<a name="line49"></a>
<a name="line50"></a>function testSizeEquals() {
<a name="line51"></a>  var a = new goog.math.Size(4, 5);
<a name="line52"></a>
<a name="line53"></a>  assertTrue(goog.math.Size.equals(a, a));
<a name="line54"></a>  assertFalse(goog.math.Size.equals(a, null));
<a name="line55"></a>  assertFalse(goog.math.Size.equals(null, a));
<a name="line56"></a>
<a name="line57"></a>  var b = new goog.math.Size(4, 5);
<a name="line58"></a>  var c = new goog.math.Size(4, 6);
<a name="line59"></a>  assertTrue(goog.math.Size.equals(a, b));
<a name="line60"></a>  assertFalse(goog.math.Size.equals(a, c));
<a name="line61"></a>}
<a name="line62"></a>
<a name="line63"></a>function testSizeArea() {
<a name="line64"></a>  var s = new goog.math.Size(4, 5);
<a name="line65"></a>  assertEquals(20, s.area());
<a name="line66"></a>}
<a name="line67"></a>
<a name="line68"></a>function testSizePerimeter() {
<a name="line69"></a>  var s = new goog.math.Size(4, 5);
<a name="line70"></a>  assertEquals(18, s.perimeter());
<a name="line71"></a>}
<a name="line72"></a>
<a name="line73"></a>function testSizeAspectRatio() {
<a name="line74"></a>  var s = new goog.math.Size(undefined, undefined);
<a name="line75"></a>  assertNaN(s.aspectRatio());
<a name="line76"></a>
<a name="line77"></a>  s.width = 4;
<a name="line78"></a>  s.height = 0;
<a name="line79"></a>  assertEquals(Infinity, s.aspectRatio());
<a name="line80"></a>
<a name="line81"></a>  s.height = 5;
<a name="line82"></a>  assertEquals(0.8, s.aspectRatio());
<a name="line83"></a>}
<a name="line84"></a>
<a name="line85"></a>function testSizeFitsInside() {
<a name="line86"></a>  var target = new goog.math.Size(10, 10);
<a name="line87"></a>
<a name="line88"></a>  var a = new goog.math.Size(5, 8);
<a name="line89"></a>  var b = new goog.math.Size(5, 12);
<a name="line90"></a>  var c = new goog.math.Size(19, 7);
<a name="line91"></a>
<a name="line92"></a>
<a name="line93"></a>  assertTrue(a.fitsInside(target));
<a name="line94"></a>  assertFalse(b.fitsInside(target));
<a name="line95"></a>  assertFalse(c.fitsInside(target));
<a name="line96"></a>}
<a name="line97"></a>
<a name="line98"></a>function testSizeScaleToFit() {
<a name="line99"></a>  var target = new goog.math.Size(512, 640);
<a name="line100"></a>
<a name="line101"></a>  var a = new goog.math.Size(1600, 1200);
<a name="line102"></a>  var b = new goog.math.Size(1200, 1600);
<a name="line103"></a>  var c = new goog.math.Size(400, 300);
<a name="line104"></a>  var d = new goog.math.Size(undefined, undefined);
<a name="line105"></a>
<a name="line106"></a>  assertEquals(&#39;(512 x 384)&#39;, a.scaleToFit(target).toString());
<a name="line107"></a>  assertEquals(&#39;(480 x 640)&#39;, b.scaleToFit(target).toString());
<a name="line108"></a>  assertEquals(&#39;(512 x 384)&#39;, c.scaleToFit(target).toString());
<a name="line109"></a>  assertEquals(&#39;(512 x 640)&#39;, target.scaleToFit(target).toString());
<a name="line110"></a>
<a name="line111"></a>  assertEquals(&#39;(NaN x NaN)&#39;, d.scaleToFit(target).toString());
<a name="line112"></a>  assertEquals(&#39;(NaN x NaN)&#39;, a.scaleToFit(d).toString());
<a name="line113"></a>}
<a name="line114"></a>
<a name="line115"></a>function testSizeIsEmpty() {
<a name="line116"></a>  var s = new goog.math.Size(undefined, undefined);
<a name="line117"></a>  assertTrue(s.isEmpty());
<a name="line118"></a>  s.width = 0;
<a name="line119"></a>  s.height = 5;
<a name="line120"></a>  assertTrue(s.isEmpty());
<a name="line121"></a>  s.width = 4;
<a name="line122"></a>  assertFalse(s.isEmpty());
<a name="line123"></a>}
<a name="line124"></a>
<a name="line125"></a>function testSizeScaleFactor() {
<a name="line126"></a>  var s = new goog.math.Size(4, 5);
<a name="line127"></a>  assertEquals(&#39;(8 x 10)&#39;, s.scale(2).toString());
<a name="line128"></a>  assertEquals(&#39;(0.8 x 1)&#39;, s.scale(0.1).toString());
<a name="line129"></a>}
<a name="line130"></a>
<a name="line131"></a>function testSizeCeil() {
<a name="line132"></a>  var s = new goog.math.Size(2.3, 4.7);
<a name="line133"></a>  assertEquals(&#39;(3 x 5)&#39;, s.ceil().toString());
<a name="line134"></a>}
<a name="line135"></a>
<a name="line136"></a>function testSizeFloor() {
<a name="line137"></a>  var s = new goog.math.Size(2.3, 4.7);
<a name="line138"></a>  assertEquals(&#39;(2 x 4)&#39;, s.floor().toString());
<a name="line139"></a>}
<a name="line140"></a>
<a name="line141"></a>function testSizeRound() {
<a name="line142"></a>  var s = new goog.math.Size(2.3, 4.7);
<a name="line143"></a>  assertEquals(&#39;(2 x 5)&#39;, s.round().toString());
<a name="line144"></a>}
<a name="line145"></a>
<a name="line146"></a>function testSizeGetLongest() {
<a name="line147"></a>  var s = new goog.math.Size(3, 4);
<a name="line148"></a>  assertEquals(4, s.getLongest());
<a name="line149"></a>
<a name="line150"></a>  s.height = 3;
<a name="line151"></a>  assertEquals(3, s.getLongest());
<a name="line152"></a>
<a name="line153"></a>  s.height = 2;
<a name="line154"></a>  assertEquals(3, s.getLongest());
<a name="line155"></a>
<a name="line156"></a>  assertNaN(new goog.math.Size(undefined, undefined).getLongest());
<a name="line157"></a>}
<a name="line158"></a>
<a name="line159"></a>function testSizeGetShortest() {
<a name="line160"></a>  var s = new goog.math.Size(3, 4);
<a name="line161"></a>  assertEquals(3, s.getShortest());
<a name="line162"></a>
<a name="line163"></a>  s.height = 3;
<a name="line164"></a>  assertEquals(3, s.getShortest());
<a name="line165"></a>
<a name="line166"></a>  s.height = 2;
<a name="line167"></a>  assertEquals(2, s.getShortest());
<a name="line168"></a>
<a name="line169"></a>  assertNaN(new goog.math.Size(undefined, undefined).getShortest());
<a name="line170"></a>}
<a name="line171"></a>
<a name="line172"></a>function testSizeScaleXY() {
<a name="line173"></a>  var s = new goog.math.Size(5, 10);
<a name="line174"></a>  assertEquals(&#39;(20 x 30)&#39;, s.scale(4, 3).toString());
<a name="line175"></a>}
</pre>


</body>
</html>
